﻿@inherits EditDrawerBase<UserDto, int>
@if (_editModel != null)
{
<Form Loading="@_isLoading"
      Model="@_editModel"
      LabelCol="new ColLayoutParam { Span = 8 }"
      WrapperCol="new ColLayoutParam { Span = 16 }"
      OnFinish="OnFormFinish"
      Context="model">
    <FormItem Label="头像">
        @if (DrawerInputType.Edit.Equals(this.Options.Type))
        {

            <Tooltip Placement="Placement.LeftTop" Title="@("点击修改头像")">
                <a @onclick="_ => OnAvatarClick(model)">
                    <Avatar Src="@model.Avatar" />
                </a>
            </Tooltip>

        }
        else if (DrawerInputType.Select.Equals(this.Options.Type))
        {
            <Avatar Src="@model.Avatar" />
        }
    </FormItem>
    <FormItem Label="部门">
        <TreeSelect TItem="DeptDto"
                    Style="width:100%;"
                    DataSource="deptDatas"
                    @bind-Value="@deptId"
                    Placeholder="@localizer["请选择"]"
                    AllowClear
                    TitleExpression="data => data.Name"
                    KeyExpression="data => data.Id.ToString()"
                    ChildrenExpression="data => data.Children?.ToList()"
                    IsLeafExpression="data => data.Children == null"
                    DataItemExpression="(deptDatas, id) => TreeTools.QueryNode<DeptDto>(deptDatas.ToArray(),item=>item.Id.ToString().Equals(id),item=>item.Children)"
                    TreeDefaultExpandAll>
        </TreeSelect>
    </FormItem>
    <FormItem Label="岗位">
        <Select DataSource="@positions"
                @bind-Value="@model.PositionId"
                ValueName="@nameof(PositionDto.Id)"
                LabelName="@nameof(PositionDto.Name)"
                OnSelectedItemChanged="OnSelectedItemChangedHandler"
                AllowClear
        >
        </Select>
    </FormItem>
    <FormItem Label="用户名">
        <Input @bind-Value="@model.UserName" />
    </FormItem>
    <FormItem Label="密码">
        <Input Type="password" @bind-Value="@model.Password" />
    </FormItem>
    <FormItem Label="昵称">
        <Input @bind-Value="@model.NickName" />
    </FormItem>
    <FormItem Label="性别">
        <RadioGroup @bind-Value="@(model.Gender)">
            @foreach (var gitem in EnumHelper.EnumToDictionary<Gender>())
            {
                <Radio Value="@(gitem.Key)">@gitem.Value</Radio>
            }
        </RadioGroup>
    </FormItem>
    <FormItem Label="是否锁定">
        <Switch @bind-Value="@model.IsLocked"></Switch>
    </FormItem>
    <Divider Orientation="left" Style="font-weight:bold">联系信息</Divider>
    <FormItem Label="手机号">
        <Input @bind-Value="@model.PhoneNumber" />
    </FormItem>
    <FormItem Label="手机号是否确认">
        <Switch @bind-Value="@model.PhoneNumberConfirmed"></Switch>
    </FormItem>
    <FormItem Label="邮箱">
        <Input @bind-Value="@model.Email" />
    </FormItem>
    <FormItem Label="邮箱是否确认">
        <Switch @bind-Value="@model.EmailConfirmed"></Switch>
    </FormItem>
    <FormItem Label="QQ">
        <Input @bind-Value="@model.UserExtension.QQ" />
    </FormItem>
    <FormItem Label="微信">
        <Input @bind-Value="@model.UserExtension.WeChat" />
    </FormItem>
    <FormItem WrapperCol="new ColLayoutParam { Offset = 4, Span = 20 }">
        <Space>
            @if (!DrawerInputType.Select.Equals(this.Options.Type))
            {
                <SpaceItem>
                    <Button Type="@ButtonType.Primary" HtmlType="submit">
                        @localizer["保存"]
                    </Button>
                </SpaceItem>
            }
            <SpaceItem>
                <Button OnClick="OnFormCancel">
                    @localizer["取消"]
                </Button>
            </SpaceItem>
        </Space>
    </FormItem>
</Form>
}